package com.smh.a05PaChongdemo5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
    public static void main(String[] args) throws IOException {

        String str = "java是一门编程语言,java9号";

        Pattern p = Pattern.compile("java\\d{0,2}");//正则
        //文本匹配器
        Matcher m = p.matcher(str);
        //m.find()就是找到第一次目标结束,重复调用依次往后找
        //记录字串的起始索引和结束索引加一
        //m.group()就是截取找到的字符串
        while (m.find()){
            method1(m);
        }

        URL url = new URL("https://www.java.com/zh-CN/");
        //创建链接
        URLConnection conn = url.openConnection();
        //读取网路数据
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

        String line;
        //做了一次修改<test>

        while ((line=br.readLine())!=null){
            //System.out.println(line);
            Matcher m1 = p.matcher(line);
            while (m1.find()){
                System.out.println(m1.group());
            }
        }
        br.close();


    }

    private static void method1(Matcher m) {
        System.out.println(m.group());
    }
}
